/**
 * 表单验证
 * @param {*} that
 * @param {*} formName
 * @returns 校验结果
 */
export const formValidate = (that, formName) => {
  let valid = false
  that.$refs[formName].validate((result) => {
    if (result) valid = true
  })
  return valid
}

/**
 * 局部表单验证
 * @param {*组件实例} that
 * @param {*表单名} formName
 * @param {*校验的属性数组或单个属性} props
 * @returns 校验结果
 */
export const formValidateField = (that, formName, props) => {
  let valid = false
  that.$refs[formName].validateField(props, (error) => {
    if (!error) {
      valid = true
    }
  })
  return valid
}

/**
 * 弹窗确认
 * @param {*this组件实例} that
 * @param {*string文本} message
 * @param {*string标题} title
 * @param {*object配置} options
 * @returns 是否确认
 */
export const confirmMsg = async (that, message, title, options) => {
  try {
    await that.$confirm(message, title, options)
    return true
  } catch (error) {
    return error
  }
}
